﻿using DocBot.Util;

using System;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;

namespace DocBot.ViewModel
{
	public class SubscriberAudioDeviceViewModel : AudioDeviceViewModel
	{
		#region Members
		int _selectedAudioDevice = -1;
		#endregion

		#region Properties
		new public int SelectedAudioDevice
		{
			get
			{
				return this._selectedAudioDevice;
			}
			set
			{
				if (value != this._selectedAudioDevice)
				{
					this._selectedAudioDevice = value;
					NotifyPropertyChanged();
				}
			}
		}
		#endregion

		#region Events
		override public event PropertyChangedEventHandler PropertyChanged;

		// This method is called by the Set accessor of each property.
		// The CallerMemberName attribute that is applied to the optional propertyName
		// parameter causes the property name of the caller to be substituted as an argument.
		private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
		{
			if (PropertyChanged != null)
			{
				PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
				if (propertyName == "SelectedAudioDevice")
				{
					Settings.Instance.VLC_SubScriberWaveOutDevice = base.AudioDevices[SelectedAudioDevice].Name;
				}
			}
		}
		#endregion

		#region Construction
		public SubscriberAudioDeviceViewModel()
		{
			if (base.AudioDevices == null)
				return;
			WaveDevices.WAVEOUTCAPS[] _devices = WaveDevices.GetDevCapsPlayback();
			for (int i = 0; i < _devices.Count(); i++)
			{
				if (_devices[i].ToString() == Settings.Instance.VLC_SubScriberWaveOutDevice)
					SelectedAudioDevice = i;
			}
		}
		#endregion
	}
}
